<!DOCTYPE html>
<html>
<head>
<title></title> <@h.head />
<script type="text/javascript"
	src="${path}/static/plugins/lhgdialog/lhgdialog.min.js"></script>
	
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
</head>
<body>
	<form action="${path}/sysuser/save" id="fm" method="post" class="definewidth m20">
		<div style="text-align: center;" id="errorMsg"></div>
		<table class="table table-bordered definewidth m10">
			<input type="hidden" id="userId" value="${(userId)!''}" name="id">
			<tr>
				<td width="10%" class="tableleft">登录名 <span class="required">*</span></td>
				<td>
					<input type="text" name="username" datatype="s4-18" calss="disabled" nullmsg="请输入用户名！" errormsg="用户名至少4个字符,最多18个字符！" />
				</td>
			</tr>
			<tr>
				<td class="tableleft">密码 <span class="required">*</span></td>
				<td>
					<input type="hidden" name="password" id="password"/>
					<a class="btn" href="javascript: reSetPwd();" >重置密码</a>
					<span id="passwordMsg"></span>
				</td>
			</tr>
			<tr>
				<td class="tableleft">昵称<span class="required">*</span></td>
				<td><input type="text" name="name" datatype="s4-18" nullmsg="请输入昵称！" errormsg="昵称至少4个字符,最多18个字符！" /></td>
			</tr>
			<tr>
				<td class="tableleft">角色<span class="required">*</span></td>
				<td>
					<input type="text" class="form-control" readonly="readonly" id="roleNameArr" name="roleNameArr" datatype="*" nullmsg="请至少选择一个角色！"/>
					<input type="text" style="display: none;" readonly="readonly" id="roleArr" name="roleArr"/>
					<a class="btn btn-small" href="javascript:void(0)" onclick="selectRoles();">选择</a>
				</td>
			</tr>
			<tr>
				<td class="tableleft">描述</td>
				<td><input type="text" name="remark"/></td>
			</tr>
			<tr>
				<td class="tableleft"></td>
				<td>
					<button type="submit" class="btn btn-primary" type="button">保存</button>
					&nbsp;&nbsp;
					<button type="button" class="btn" name="backid"
						id="backid">返回列表</button>
				</td>
			</tr>
		</table>
	</form>
	<@h.foot />
	<script type="text/javascript">
		$(function() {
			$('#backid').click(function() {
				window.location.href = "${path}/sysuser/list";
			});
			
			var userVal = $("#userId").val();
			if (userVal != null && userVal != 0) {
				var url = "${path}/sysuser/getById/" + userVal;
				$.get(url, function(data) {
					var data = eval('(' + data + ')');
					$("#fm").jsonData(data.data);
					$(".disabled").attr("readOnly", "readOnly");
				});
			};
		});
		var callback = function(data) {
			if (data.status == "200") {
				window.location.href = "${path}/sysuser/list";
			} else {
				$("#errorMsg").html(data.msg).show();
			}
		}
		$("#fm").validFrom(callback);
		
		function selectRoles(){
			$.dialog({
			    lock: true,
			    title: '角色分配',
			    background: '#FFF', /* 背景色 默认的遮罩背景色为:#DCE2F1浅蓝护眼色 */
			    opacity: 0.5,       /* 透明度 */
			    content: 'url:${path}/sysuser/roles?id=' + ${(userId)!''},
			    height: 300,
			    ok: function () {
			    	return false;
			    },
			    cancel: true
			});
		}
		
		function reSetPwd(){
			// 重置密码为MD5(123456)
			document.getElementById('password').value = 'e10adc3949ba59abbe56e057f20f883e';
			$("#passwordMsg").html('重置密码为123456，保存后生效').show();
		}
	</script>
</body>
</html>